#include "sprite_scroll.h"

namespace SkyID
{

//- SpriteScroll --------------------------------------------------------------

SpriteScroll::SpriteScroll(const Texture *texture, float speed) :
	Sprite(texture, 0.0f, 0.0f, texture->getWidth(), texture->getHeight())
{
	mSpeed = speed;
	mScroll = 0.0f;
}

SpriteScroll::~SpriteScroll()
{
	//
}

void SpriteScroll::update(float dt)
{
	if (mSpeed != 0.0f)
		scrollTexture(dt * mSpeed);
}

void SpriteScroll::scrollTexture(float delta)
{
	float width = mWidth * 2.0f;

	mScroll += delta;

	while (mScroll >= width)
		mScroll -= width;
	while (mScroll <= -width)
		mScroll += width;

	setTextureRect(mScroll, 0.0f, mWidth, mHeight);
}

} // namespace SkyID
